import loadjs from 'loadjs';
let baseurl = process.env.BASE_URL;

const depMaps = {
  // versions: echarts 4.2.1, Swiper 3.4.2
  echarts: [`${baseurl}script/echarts.min.js`],
  swiper: [`${baseurl}script/swiper.min.css`, `${baseurl}script/swiper.min.js`],
};

const depStatus = {};

export default {
  loadEcharts: async function() {
    const label = 'echarts';
    if (!depStatus[label]) {
      await loadjs(depMaps[label], { returnPromise: true });
      depStatus[label] = true;
    }
  },
  loadSwiper: async function() {
    const label = 'swiper';
    if (!depStatus[label]) {
      await loadjs(depMaps[label], { returnPromise: true });
      depStatus[label] = true;
    }
  },
};
